package com.controller;

import com.entity.PageBean;
import com.entity.Product;
import com.service.ProductService;
import com.service.impl.ProductServiceImpl;
import com.utils.Constants;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;

/**
 * @ProjectName: shop
 * @Author: Jsx
 * @Time: 2020/8/30 21:33
 * @Description:
 */
@WebServlet("/product")
public class ProductController extends BaseController {

    /**
     * 商品分页展示
     * @param request
     * @param response
     * @return
     * @throws SQLException
     */
    public String getProducts(HttpServletRequest request, HttpServletResponse response) throws SQLException {

        //1.获取请求参数
        String tid = request.getParameter("tid");
        String currentPage = request.getParameter("currentPage");
        String pageSize = request.getParameter("pageSize");

        //2.调用业务逻辑
        ProductService productService = new ProductServiceImpl();
        PageBean<Product> pageBean = productService.findAll(tid, currentPage, pageSize);

        //3.响应
        request.setAttribute("pageBean",pageBean);

        return Constants.FORWARD_ACTION + "/goodsList.jsp";

    }

}
